package asteroids.model.programs.parsing.expressions;

import java.util.List;
import java.util.Map;

import asteroids.model.programs.parsing.types.EntityLiteral;
import asteroids.model.programs.parsing.types.Type;

/**
 * A class of entity expressions.
 * An entity expression involves an operator applied to an entity.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public abstract class EntityExpr extends UnOpExpr {

	public EntityExpr(Expression expression,int line, int column) {
		super(expression, line,column);
	}

	@Override
	public  List<String> getTypeCheckErrors(List<String> errors, Map<String, Type> globals){
		errors= getOperand().getTypeCheckErrors(errors, globals);
		try{
			if(getOperand().eval(null, globals).getClass()!=EntityLiteral.class){
				errors.add(getLine()+"-"+getColumn()+": No valid entity given");
			}
		}
		catch(NullPointerException e){
			errors.add("No valid entity given");
		}
		return errors;
	}
}
